package com.skycode7.util;

import java.sql.Connection;
import java.sql.DriverManager;

public class DBConnection {
    private String FileName;
    private int DBType;
    private Connection conn;
    private String MySqlDriver;
    private String MySqlURL;
    public DBConnection(){
        conn = null;
    }
    public Connection getConn(){
        DBType = 1;
        switch (DBType){
            case 1:return (getConnToMySql());
            default:return null;
        }
    }
    public Connection getConnToMySql(){
        try{
            // 8.0加.cj 小于5.7不加
            MySqlDriver = "com.mysql.cj.jdbc.Driver";
            MySqlURL = "jdbc:mysql://localhost:3306/sky_code?user=root&password=888888"+
                    "&Unicode=true&characterEncoding=UTF-8";
            Class.forName(MySqlDriver).newInstance();
            conn = DriverManager.getConnection(MySqlURL);
        }catch (Exception e){
            e.printStackTrace();
        }
        return conn;
    }
}
